<script >
export default {
     data(){
       return{
         def_url:"user_list",
         menus:[],
         menus_icon:["el-icon-s-tools","el-icon-s-custom","el-icon-s-shop","el-icon-s-order","el-icon-s-marketing","el-icon-s-order"]
       }
     },
  created() {
    //调用获取菜单的函数
    this.getMenus()
    const url = window.sessionStorage.getItem("url")
    if(url){
      this.def_url=url
    }
  },
  computed: {
    name() {
      return sessionStorage.getItem("name")
    },
    icon() {
      return sessionStorage.getItem("icon")
    }
  },
  methods: {
    changeActiveMenu(url){
      if(url!=null&&""!==url){
        window.sessionStorage.setItem('url',url)
      }
    },
    showUser() {
      this.$axios.get("user/listUser")
          .then(res => {
            console.log(res)
          })
    },

    exit() {
      window.localStorage.clear()
      window.sessionStorage.clear()
      this.$router.push("/login")
    },
    //获取菜单列表
    async getMenus(){
      let {data:res} =  await this.$axios.get("menus/getMenus")
      console.log(res.data)
      this.menus = res.data
    }

  }
}


</script>
<template>
  <el-container class="el-container">
    <el-header class="el-header">
      <img src="@/assets/logo.png" class="logo" >
      <h4>无畏契约管理系统</h4>
      <div class="userInfo" >
        <img  class="icon" :src="icon" >
        <span>{{name}}</span>
        <el-button type="primary"  @click=exit size="mini" round >退出</el-button>
      </div>
    </el-header>
    <el-container class="el-container">
      <!--侧栏区域-->
      <el-aside class="el-aside" width="200px">
        <!--菜单区域 -->
        <el-menu
            :default-active="this.def_url"
            router
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
          <!--一级菜单-->
          <el-submenu :index="menu.id+''"  v-for="(menu,index) in menus">
            <template slot="title">
              <i :class="menus_icon[index]"></i>
              <span>{{menu.name}}</span>
            </template>
            <!--              二级菜单-->
            <el-menu-item  :index="son_menu.url" @click="changeActiveMenu(son_menu.url)" v-for="son_menu in menu.son_menus">
              <template slot="title">
                <i class="el-icon-date"></i>
                <span>{{son_menu.name}}</span>
              </template>

            </el-menu-item>

          </el-submenu>


        </el-menu>
      </el-aside>
      <el-container>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer>Footer</el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>

<style>
.el-header {
  display: flex; /* 启用 Flexbox 布局 */
  justify-content: space-between; /* 使元素左右对齐 */
  align-items: center; /* 垂直居中对齐 */
}

.el-header, .el-footer {
  background-color: rgb(53, 61, 64);
  color: white;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: rgb(4, 42, 61);
  color: #333;
  line-height: 200px;
  height: 100%;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
}

.el-container {
  height: 100%;
}

.logo {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  vertical-align: middle;
  margin-top: 5px;
}

.icon {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  vertical-align: middle;
}
.userInfo{
  width: 12%;
}
.userInfo>span{
  margin: auto 10px;
}
</style>
